<?php

namespace App\Traits;


use App\Enums\ReportEnums;

class External
{
    public static function optionResultSimple($result)
    {
        $arr = [];
        foreach ($result as  $key => $item){
//            $item->status_name = ReportEnums::getDescription($item->status);
            $arr[$key] = $item->toArray();
            if(!empty($item->mid)) {
                $arr[$key]['base']['username'] = $item->hasOneMember->username;
                $arr[$key]['base']['realname'] = $item->hasOneMember->realname;
                $arr[$key]['base']['avatar'] = $item->hasOneMember->avatar;
                $arr[$key]['base']['sn'] = $item->hasOneMember->sn;
            }else{
                $arr[$key]['base'] = [];
            }

            if(!empty($item->otherid)) {
                $arr[$key]['obase']['username'] = $item->hasOneOtherMember->username;
                $arr[$key]['obase']['realname'] = $item->hasOneOtherMember->realname;
                $arr[$key]['obase']['avatar'] = $item->hasOneOtherMember->avatar;
                $arr[$key]['obase']['sn'] = $item->hasOneOtherMember->sn;
            }else{
                $arr[$key]['obase'] = [];
            }

            if(!empty($item->maker_id)) {
                $arr[$key]['realname'] = $item->hasOneUser->realname ?: '' ;
            }
        }
        return $arr;
    }

    public static function optionResultSingle($result,$type)
    {
        $arr = [];
        if($type == 1){
            //获取mid相关用户信息
            foreach ($result as $key => $item){
                $arr[$key] = $item->toArray();
                $arr[$key]['username'] = $item->hasOneMember->username;
                $arr[$key]['realname'] = $item->hasOneMember->realname;
                $arr[$key]['avatar'] = $item->hasOneMember->avatar;
                $arr[$key]['sn'] = $item->hasOneMember->sn;
            }
        }
        if($type == 2){
            //获取otherid相关用户信息
            foreach ($result as $key => $item){
                $arr[$key] = $item->toArray();
                $arr[$key]['username'] = $item->hasOneOtherMember->username;
                $arr[$key]['realname'] = $item->hasOneOtherMember->realname;
                $arr[$key]['avatar'] = $item->hasOneOtherMember->avatar;
                $arr[$key]['sn'] = $item->hasOneOtherMember->sn;
            }
        }
        if(!empty($item->maker_id)) {
            $arr[$key]['realname'] = $item->hasOneUser->realname ?: '' ;
        }
        return $arr;
    }
}
